<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class Routes extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $routesModel = $this->table('routes');
        $routesModel
        ->addColumn('pid','integer',['signed'=>false,'comment'=> '上级菜单'])
        ->addColumn('name','string',['limit'=>32,'comment'=> '菜单名称'])
        ->addColumn('redirect','string',['limit'=>32,'comment'=> '跳转url'])
        ->addColumn('componentStr','string',['limit'=>32,'comment'=> '前端组件'])
        ->addColumn('path','string',['limit'=>32,'comment'=> '前端路径'])
        ->addColumn('meta','json',['default'=>'','comment'=> '其他配置项'])
        ->addColumn('create_time', 'datetime')
        ->addColumn('update_time', 'datetime')
        ->addColumn('status', 'integer', ['default'=>1,'comment'=>'用户状态 0无效 1有效'])
        ->create();



        $data = [
            ['pid' => 0, 'name' => '权限管理', 'redirect' => '/role/list',
                'componentStr' => '',                   'path' => '/config',            'meta' => '{"affix": false, "title": "权限管理", "elIcon": "User", "hidden": false, "svgIcon": "", "activeMenu": "/config", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
            ['pid' => 1, 'name' => '角色列表', 'redirect' => '',
                'componentStr' => 'list/list.vue',      'path' => '/role/List',         'meta' => '{"affix": false, "title": "角色列表", "elIcon": "Avatar", "hidden": false, "svgIcon": "", "activeMenu": "/config", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
            ['pid' => 1, 'name' => '用户列表', 'redirect' => '',
                'componentStr' => 'list/list.vue',      'path' => '/user/List',         'meta' => '{"affix": false, "title": "用户列表", "elIcon": "UserFilled", "hidden": false, "svgIcon": "", "activeMenu": "/config", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
            ['pid' => 1, 'name' => '菜单列表', 'redirect' => '',
                'componentStr' => 'list/list.vue',      'path' => '/routes/List',       'meta' => '{"affix": false, "title": "菜单列表", "elIcon": "Menu", "hidden": false, "svgIcon": "", "activeMenu": "/config", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
            ['pid' => 1, 'name' => '菜单接口', 'redirect' => '',
                'componentStr' => 'list/list.vue',      'path' => '/routesApi/list',     'meta' => '{"affix": false, "title": "菜单接口", "elIcon": "Switch", "hidden": false, "svgIcon": "", "activeMenu": "/config", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
            ['pid' => 0, 'name' => '插件管理', 'redirect' => '/plug/list',
                'componentStr' => 'log/list.vue',       'path' => '/plugs',             'meta' => '{"affix": false, "title": "插件", "elIcon": "Tools", "hidden": false, "svgIcon": "", "activeMenu": "/plugs", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
            ['pid' => 6, 'name' => '插件列表', 'redirect' => '',
                'componentStr' => 'list/list.vue',      'path' => '/plug/list',               'meta' => '{"affix": false, "title": "插件列表", "elIcon": "Tools", "hidden": false, "svgIcon": "", "activeMenu": "/plugs", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
            ['pid' => 6, 'name' => '插件上传', 'redirect' => '',
                'componentStr' => 'plug-in/upload.vue', 'path' => '/plug/upload',             'meta' => '{"affix": false, "title": "插件上传", "elIcon": "Upload", "hidden": false, "svgIcon": "", "activeMenu": "/plugs", "alwaysShow": false, "breadcrumb": true}',
                'create_time' => date('Y-m-d H:i:s'), 'update_time' => date('Y-m-d H:i:s'), 'status' => 1],
        ];
        $routesModel->insert($data)->saveData();
    }
}
